import { defineStore, acceptHMRUpdate } from 'pinia';
import { computed, ref } from 'vue';
// import { getToken, removeToken, setToken } from '@/utils/auth';
import cache from '@/plugins/cache';

export const useMapStore = defineStore(
    'map',
    () => {
        // 地图信息
        const token = ref<string>(cache.local.get('token') || '');
        const locale = computed(() => {
            return token;
        });
        //删除token
        const delMap = () => {
            token.value = '';
        };
        return { token, locale, delMap };
    },
    {
        // 开启持久化
        persist: true
    }
);

// store/user.ts
export const useUserStore = defineStore('user', {
    state: () => ({
        token: localStorage.getItem('token') || '',
        roles: [] as string[]
    }),
    persist: true // 启用持久化插件
});

if (import.meta.hot) {
    import.meta.hot.accept(acceptHMRUpdate(useMapStore, import.meta.hot));
}
